<template>
  <div class="c_policy_declare_person">
    <!-- banner -->
    <div class="banner">
      <img src="../../assets/images/banner.png" alt />
    </div>
    <div class="box">
      <div class="location">
        <router-link to="/policy">{{$t('common.nav.policy')}}</router-link>
        <span class="sp">></span>
        <router-link to="/c_policy_list?type=policyDeclare">{{$t('common.leftNav.policy')}}</router-link>
        <!-- <span v-if="tabStatus == 'match'">{{$t('common.policy.match')}}</span> -->
        <span class="sp">></span>
        {{$t('news.detail')}}
      </div>

      <div class="box-content white" v-if="con.title.length>0">
          <h2>{{con.title}}<el-tag>{{con.applyStatusTxt}}</el-tag></h2>
          <p class="p1">
              <span>政策申报</span>
              <span>发布时间：{{con.createTime}}</span>
          </p>
          <p class="p2">
            <span>源政策：</span>
            <a href="javascript:void(0)">崖州湾科技人才管理政策</a>
          </p>
          <p class="p3">
            <span>申报主体：</span>{{con.subjectTypeTxt}}
          </p>

          <p class="p4">
            <span>申报时间：</span>
            {{con.beginTime}}   至   {{con.beginTime}}
            <span>（注：超过申报时间将不允许提交申报材料）</span>
          </p>
          <p class="p5" v-html="con.briefContent"></p>
          <h2>申报填写</h2>
          <div class="re">
            <!-- declareStatus -1暂存，0已提交，1,审核通过，2审核打回 -->
            <!-- applyStatus - 1 报名中 -->
            <div class="tipBoxs" @click="tipBoxs" v-if="userInfo.type == 1 || con.applyStatus != 1  || con.declareStatus == 0 || con.declareStatus == 1"></div>
            <el-form :inline="true" class="demo-form-inline">
              <el-form-item label="申报人姓名">
                <el-input placeholder="申报人姓名" v-model="con.applyName"></el-input>
              </el-form-item>
              <el-form-item label="性别" >
                <el-radio v-model="con.sex" label="0">男</el-radio>
                <el-radio v-model="con.sex" label="1">女</el-radio>
              </el-form-item>
            </el-form>
            <dl>
              <dt>申报材料</dt>
              <dd v-for="(item, index) in con.applyMaterialList" :key="index">
                <el-row :gutter="20" class="flex1 flex-bect">
                  <el-col :span="6">
                    <span>{{item.name}}</span>
                  </el-col>
                  <el-col :span="6">
                    <span class="h88">{{item.requirement}}</span>
                  </el-col>
                  <el-col :span="8">
                    <div @click="getYgFileIndex(index)" class="flex-lect">
                      <el-upload
                        class="honor-upload"
                        action=""
                        :show-file-list="false"
                        :before-upload="fileUpload"
                      >
                        <a href="javascript:void(0)">材料上传</a>
                      </el-upload>
                      <div class="mle10" v-if="item.userUploadAttachment && item.userUploadAttachment.name">
                        {{item.userUploadAttachment.name}}
                        <span class="red0 mle10 cur" @click="delQY(index)">删除</span>
                      </div>
                    </div>
                  </el-col>
                  <el-col :span="4" class="tr">
                    <a v-if="item.attachment && item.attachment.path" :href="imgUrl+item.attachment.path" download="" class="red1 undline" >模板下载</a>
                  </el-col>
                </el-row>
                  
              </dd>
            </dl>
            <el-form :inline="true" class="text-center">
              <el-form-item>
                  <el-button type="primary" @click="formSubmit(0)">确定提交</el-button>
                  <el-button @click="formSubmit(-1)">暂存一下</el-button>
                </el-form-item>
            </el-form>
          </div>
          
      </div>
      
    </div>
  </div>
</template>
<script>
import {ajax,showToast,ajaxAdd} from '@/utils/js.js'
import { 
  getDeclarationIssuedUserDetail,uploadFile,saveDeclarationIssuedUserDetail
   } from '@/services/api.js'
  export default {
    components: {},
    data() {
      return {
        userInfo : this.$store.state.userInfo,
        imgUrl:this.$store.state.imgUrl,
        radio: '0',
        checked:true,
        banner: [],
        con:{title:'',sex:0},
        form:{
          "applyMaterialList": [
              {
                "applyMaterialName": "",
                "attachmentId": "",
                "attachmentName": "",
                "attachmentPath": "",
                "materialId": "",
                "requirement": "",
                "templatePath": ""
              }
            ],
            "applyStatus": "",
            "applyStuffName": "",
            "applyStuffSex": "",
            "beginTime": "",
            "briefContent": "",
            "cashIn": "",
            "declarationApplyId": "",
            "declarationIssuedId": "",
            "endTime": "",
            "policyArticlesTitle": "",
            "releaseTime": "",
            "status": "",
            "subjectType": "",
            "title": ""
        },
        con1:{},
        ygFileIndex:99999,
        pagination:{
          current:1,
          size:10,
          total:132,
        },
        tabStatus:''
      };
    },
    mounted() {
      let data = this.$route.query;
      this.content(data.id);
      this.tabStatus = data.type
    },
    computed: {},
    watch: {
      "$i18n.locale"() {
        this.content();
      },
    },
    methods: {
      upTip(){
        const loading = this.$loading({
          lock: true,
          text: this.$t('common.status.upImgTip'),
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        return loading
      },
      tipBoxs(){
        // rzstatus 1未认证，2认证待审核，3已认证,4认证不通过"
        var userInfo = this.$store.state.userInfo;
        console.log(userInfo)
        // declareStatus    -1暂存，0已提交，1,审核通过，2审核打回
        if(this.con.declareStatus == 0) return showToast(this,'您已有申报记录 不能重复提交申请哦~')
        if(this.con.applyStatus == 0) return showToast(this,'还未开始申报，敬请期待！')
        if(this.con.applyStatus == 2) return showToast(this,'申报已截止！')
        if(userInfo.type == 1) return showToast(this,'只有个人身份才可申报！')
      },
      delQY(index){
        this.con.applyMaterialList[index].userUploadAttachment = null
      },

      formSubmit(e){
        let data = this.con
        console.log(data)
        if(!data.applyName || data.applyName.length == 0 ) return showToast(this,'请填入申报人姓名')
        for(let i = 0; i < data.applyMaterialList.length; i++){
          let item = data.applyMaterialList[i]
          if(!item.userUploadAttachment) return showToast(this,'请上传'+item.name)
        }
        data.declareStatus = e;
        this.con.declareStatus = e;
        ajax(this,saveDeclarationIssuedUserDetail,this.con,res=>{
          console.log('提交',res)
          showToast(this,res.msg,1)
        },err=>{})
      },
      // 个人材料上传-当前数据
      getYgFileIndex(index){
        this.ygFileIndex = index
      },
      // 个人材料上传
      fileUpload(file) {
        let loading = this.upTip()
        document.getElementsByTagName('body')[0].className = 'password'; //设置为新的
        let data = new FormData();
        data.append('file', file);
        ajax(this, uploadFile, data, res => {
          loading.close();
          document.getElementsByTagName('body')[0].className = ''; //设置为新的
          showToast(this,res.msg,1)
          this.con.applyMaterialList[this.ygFileIndex].userUploadAttachment = res.data
        });
        
      },
      content(id) {
        ajax(this,getDeclarationIssuedUserDetail,{declarationIssuedId:id},res=>{
          console.log(res)
            console.log(res);
            res.data.sex = "0"
            this.con=res.data;
            this.con1 = JSON.parse(JSON.stringify(this.con))
          },err=>{
            showToast(this,err.msg)
          })
      },
      onSubmit(){

      },
      //首页跳转
      indexLink(data) {
        if (data.outLink && data.outLink == 1) {
          window.open(data.linkUrl, "-blank");
        } else {
          window.location.href = data.linkUrl;
        }
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.search.pageNo=val;
        this.getContentList();
      },
    },
  };
</script>
<style lang="scss">
.c_policy_declare_person {
  .tipBoxs{position: absolute;width: 100%;height: 100%;z-index: 999;left:0;top:0;cursor: pointer;}
  .box-center {
    margin: 30px auto 50px auto;
    text-align: center;
  }
  .text-center{
    text-align: center;
  }
  .record{
    padding: 8px 0;
    font-size:12px;
    font-family:Microsoft YaHei;
    font-weight:400;
    line-height:16px;
    color:rgba(153,153,153,1);
    opacity:1;
  }
  .banner {
    img {
      max-width: 100%;
      min-width: 1200px;
      display: block;
    }
    .el-carousel--button {
      width: 12px;
      height: 12px;
      background: rgba(255, 255, 255, 1);
      border-radius: 50%;
      opacity: 1;
    }
    .el-carousel--indicator.is-active button {
      background-color: #0f54bc;
    }
  }
  .noRecord {
    text-align: center;
    padding: 144px 0;
    border-top: 1px solid rgba(204, 204, 204, 1);
    p:first-child {
      text-align: center;
    }
    p:nth-child(2) {
      margin-top: 25px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: rgba(153, 153, 153, 1);
      opacity: 1;
    }
    p:last-child {
      margin-top: 36px;
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: rgba(119, 119, 119, 1);
      opacity: 1;
      a {
        margin-left: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: rgba(15, 84, 188, 1);
        opacity: 1;
        text-decoration: underline;
      }
    }
  }
  .white {
    background: #fff;
  }
  .box {
    box-sizing: border-box;
    width: 1200px;
    margin: 0 auto;
    .breadcrumb-nav {
      font-size: 13px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: rgba(153, 153, 153, 1);
      opacity: 1;
      margin: 8px 0;
    }
    .box-content {
      margin-top: 6px;
      padding:18px 120px;
      h2:first-child{
        margin-top: 34px;
        text-align: center;
        font-size:22px;
        font-family:Microsoft YaHei;
        font-weight:bold;
        line-height:29px;
        color:rgba(51,51,51,1);
        opacity:1;
        .el-tag{
          margin-left: 10px;
          font-size:12px;
          font-family:Microsoft YaHei;
          font-weight:400;
          line-height:24px;
          color:rgba(15,84,188,1);
          opacity:1;
          background:rgba(15,84,188,0.1);
        }
      }
      p.p1{
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: center;
        span{
          margin:16px 15px;

        }
      }
       p.p2{
        margin: 10px 0;
        font-size:14px;
        font-family:Microsoft YaHei;
        font-weight:400;
        line-height:24px;
        color:rgba(51,51,51,1);
        opacity:1;
        a{
          font-size:14px;
          font-family:Microsoft YaHei;
          font-weight:400;
          line-height:24px;
          color:rgba(15,84,188,1);
          opacity:1;
        }
        span{
          margin-right:34px;
        }
      }
      p.p3{
        margin: 6px 0;
        font-size:14px;
        font-family:Microsoft YaHei;
        font-weight:400;
        line-height:24px;
        color:rgba(51,51,51,1);
        opacity:1;
        span{
          margin-right:20px;
        }
      }
      .el-form 
      {
        padding-top: 25px;
        border-top:1px solid rgba(239,239,239,1);
        .el-input__inner{
          width: 361px;
          margin-right: 60px;
        }
        .el-button:first-child{
          width:100px;
          height:36px;
          background:rgba(15,84,188,1);
          opacity:1;
          border-radius:2px;
          font-size:14px;
          font-family:MicrosoftYaHei;
          color:rgba(255,255,255,1);
          opacity:1;
        }
        .el-button:last-child{
          width:100px;
          height:36px;
          border:1px solid rgba(15,84,188,1);
          opacity:1;
          border-radius:2px;
          font-size:14px;
          font-family:MicrosoftYaHei;
          color:rgba(15,84,188,1);
          opacity:1;
        }
      }
      p.p4{
        margin: 12px 0;
        font-size:14px;
        font-family:Microsoft YaHei;
        font-weight:400;
        line-height:24px;
        color:rgba(51,51,51,1);
        opacity:1;
        span:first-child{
          margin-right:18px;
        }
        span:last-child{
          margin-left:12px;
          color:rgba(153,153,153,1);
        }
      }
      h3{
        font-size:14px;
        font-family:Microsoft YaHei;
        font-weight:400;
        line-height:24px;
        color:rgba(51,51,51,1);
        opacity:1;
        margin-bottom: 24px;
      }
      p.p5{
        font-size:14px;
        font-family:Microsoft YaHei;
        font-weight:400;
        line-height:24px;
        color:rgba(51,51,51,1);
        opacity:1;
        padding-bottom: 30px;
      }
      h2:nth-of-type(2){
        font-size:20px;
        font-family:Microsoft YaHei;
        font-weight:bold;
        line-height:24px;
        color:rgba(51,51,51,1);
        opacity:1;
        border-left:3px solid rgba(15,84,188,1);
        padding-left: 5px;
        margin-top:24px;
        margin-bottom: 19px;
      }
      .el-row{
        .el-col span{
          display: inline-block;
        }
      }
      dl{
        border:1px solid rgba(239,239,239,1);
        dt{
          font-size:14px;
          font-family:Microsoft YaHei;
          font-weight:bold;
          line-height:19px;
          color:rgba(51,51,51,1);
          opacity:1;
          padding: 14px 22px;
          background: #f6f6f6;
        } 
        dd{
          display: flex;
          flex-direction: row;
          flex-wrap: nowrap;
          justify-content: space-between;
          font-size:14px;
          font-family:Microsoft YaHei;
          font-weight:400;
          line-height:19px;
          padding:13px 22px;
          color:rgba(51,51,51,1);
          opacity:1;
          border-bottom: 1px solid rgba(239,239,239,1);
          span:nth-of-type(2){
            font-size:12px;
            font-family:Microsoft YaHei;
            font-weight:400;
            line-height:24px;
            color:rgba(153,153,153,1)!important;
            opacity:1;
          }
          a{
            font-size:14px;
            font-family:Microsoft YaHei;
            font-weight:400;
            line-height:24px;
            color:rgba(15,84,188,1);
            opacity:1;
            text-decoration: underline;
          }
          a:last-child{
            font-family:Microsoft YaHei;
            font-weight:400;
            line-height:19px;
            font-size: 12px;
            color:rgba(153,153,153,1);
            text-decoration: none;
          }
          a:last-child:hover{
            color:rgba(15,84,188,1);
          }
        }
        dd:last-child{
          border:none;
        }
      }
      p.tips{
        font-size:12px;
        font-family:Microsoft YaHei;
        font-weight:400;
        line-height:16px;
        padding:4px 22px;
        color:rgba(153,153,153,0.99);
      }
      .mt30{
        margin-top:30px;
      }
    }
  }
}
</style>